/*
                    Frame Class Definition
*/

#ifndef FRAME_H
#define FRAME_H

#include <vector>
#include <queue>
#include <map>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

#include "Widget.h"
#include "GUIEvent.h"
#include "GUIDefinitions.h"
#include "../Structs.h"
#include "../Functions.h"
//#include "../CursorEngine.h"

#include "Button.h"
#include "Checkbox.h"
#include "Imagebox.h"
#include "Label.h"
#include "Listbox.h"
#include "TextBox.h"
#include "VScrollbar.h"
#include "Chatbox.h"
#include "Pushbutton.h"
#include "Statbar.h"

using namespace std;

#define ALIGN_TOP       0x00
#define ALIGN_BOTTOM    0x01
#define ALIGN_LEFT      0x02
#define ALIGN_RIGHT     0x03
#define ALIGN_CENTER    0x04

class FrameTab
{
    public:
        FrameTab();
        ~FrameTab();

        int AddWidget(Widget *pNewWidget);

        int Hide();
        int Show();

        void setName(const string& strNewName);
        string getName();

    private:
        string strName;
        vector<Widget*> Widgets;
};

class Frame
{
      public:
             Frame();
             virtual ~Frame();

             virtual int Initialise(Point NewPosition, int iNewWidth, int iNewHeight);

             virtual int HandleMouseDown(int iMouseX, int iMouseY);
             virtual int HandleMouseUp(int iMouseX, int iMouseY);
             virtual int HandleMouseMotion(int iMouseXREL, int iMouseYREL);
             virtual int HandleWindowResize(int iWindowWidth, int iWindowHeight);
             virtual int HandleKeyDown(string strKeyName, Uint16 UNICODEvalue);

             virtual int AddWidget(Widget *pNewWidget, string strWidgetName);

             virtual void setVisible(bool bNewVisible);
             virtual bool getVisible();
             virtual void ToggleVisible();

             virtual int BlitToSurface(SDL_Surface *surface);

             virtual int PollEvent(GUIEvent &event);

             virtual int setBackground(SDL_Surface *NewBackground);
             virtual int setBackground(string strFilepath);

             virtual bool CheckFocus(int iMouseX, int iMouseY);

             virtual Point getPosition();
             virtual void setPosition(Point NewPos);

             virtual void setName(string strNewName);
             virtual string getName();

             virtual void setFixed(bool bNewFixed);

             virtual void MoveRelative(int iXREL = 0, int iYREL = 0);

             virtual int CreateTab(const string& strTab);
             virtual int AddWidgetToTab(const string& strTab, Widget *pNewWidget);
             virtual int SetVisibleTab(const string& strTab);

             virtual void WindowAlign(const int& iAlignType, const Point WindowSize);

      protected:
              vector<Widget*> Widgets;
              map<string, FrameTab*> Tabs;
              queue<GUIEvent*> EventBuffer;

              string strName;

              Point Position;

              bool bVisible, bFixed, bDragging, bHasFocus;

              int iWidth, iHeight;

              SDL_Surface *Background;

              int GetWidgetByName(string strName);
};

#endif
